﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Objects.SqlClient;

namespace EntityFramework
{
    public class ProductsBO : BaseBO
    {
        public static List<Product> GetTopProductIsFocusHome(int top, int zoneId = 0 , int companyID = 0)
        {
            using (var _db = new DbWebsite())
            {
                return _db.StoredProcedures.GetTopProductIsFocusHome(top, zoneId, companyID);
            }
        }
        public static List<Product> GetTopProductIsFocus(int top, int zoneId = 0)
        {

            return
                db.Products.Where(d => (zoneId == 0 || zoneId == d.ZoneId))
                    .OrderByDescending(d => d.id).Take(top)
                    .ToList();

        }

        public static List<Product> GetPagingProductByZoneProduct(int pageIndex, int pageSize, int zoneId, int CompanyID)
        {
            using (var _db = new DbWebsite())
            {
                return _db.StoredProcedures.GetPagingProductByZoneProduct(pageIndex, pageSize, zoneId, CompanyID);
            }
        }

        public static int GetCountVisit(long productID)
        {
            var count = 0;
            using (var _db = new DbWebsite())
            {
                count = _db.StoredProcedures.GetCountVisit(productID);
            }
            return count;
        }

        public static int GetPagingNumber(int zoneId, int pageSize, int CompanyID)
        {
            var count = 0;
            using (var _db = new DbWebsite())
            {
                count = _db.StoredProcedures.GetPagingNumber(zoneId, CompanyID);
            }
            int pageNum = 0;
            pageNum = (int)Math.Ceiling((double)count / pageSize);
            if (pageNum * pageSize < count)
            {
                pageNum++;
            }
            return pageNum;
        }

        public static Product GetProductDetail(long productID)
        {

            using (var _db = new DbWebsite())
            {
                return _db.StoredProcedures.GetProductDetail(productID);
            }


        }

        public static List<Product> GetRelationProduct(string productIds)
        {
            using (var _db = new DbWebsite())
            {
                return _db.StoredProcedures.GetRelationProduct(productIds);
            }
        }
    }
}
